//
//  SelectedNumberView.m
//  CaiPiao
//
//  Created by apple on 2018/5/19.
//  Copyright © 2018年 apple. All rights reserved.
//


#define kBGNormalColor [UIColor colorWithRed:(239/255.0) green:(239/255.0) blue:(244/255.0) alpha:1]
#define kTextSelectedColor [UIColor whiteColor]

#import "SelectedNumberView.h"

@implementation SelectedNumberView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    self.numberLabel.layer.masksToBounds = YES;
    self.numberLabel.layer.cornerRadius = self.numberLabel.frame.size.width*0.5;
    self.numberLabel.layer.borderWidth = 1;
    self.numberLabel.layer.borderColor = self.numberMainColor.CGColor;
    [self setNormalState];
}

-(void)setNormalState{
    self.isSelected = NO;
    self.userInteractionEnabled = YES;
    self.numberLabel.backgroundColor = kBGNormalColor;
    self.numberLabel.textColor = self.numberMainColor;
    if (self.TapCallback) {
        self.TapCallback(self.isSelected, self.numberLabel.text);
    }
}

-(void)setHighLightState{
    self.isSelected = YES;
    self.userInteractionEnabled = YES;
    self.numberLabel.backgroundColor = self.numberMainColor;
    self.numberLabel.textColor = kTextSelectedColor;
    if (self.TapCallback) {
        self.TapCallback(self.isSelected, self.numberLabel.text);
    }
}

-(void)numberSelected{
    self.userInteractionEnabled = NO;
    [UIView animateWithDuration:0.1 animations:^{
        self.numberLabel.transform = CGAffineTransformMakeScale(1.2, 1.2);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            self.numberLabel.transform = CGAffineTransformMakeScale(1, 1);
        } completion:^(BOOL finished) {
            if (self.isSelected) {
                [self setNormalState];
            }else{
                [self setHighLightState];
            }
        }];
    }];
}

- (IBAction)selectedNumberAction:(id)sender {
    [self numberSelected];

}


@end
